<?
/*  HTTP POST and GET implementation
 *  using CURL functions.
 *  @author Vladimir Miroshnichenko
 */
class Http
{
	/* constuctor */
	function Http(){
//	$config_bo=new ConfigurationBO();
//	$config_bo->refreshConfigValue('DownloadTimeout');
	}
	
	function POST($url,$postfields,$cookiefile,$filename,$proxy="",$useragent="Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)")
	{
		global $configuration;
		$ch = curl_init();
		if($cookiefile!="") curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiefile);
		curl_setopt($ch, CURLOPT_URL,$url);
		curl_setopt($ch, CURLOPT_POST, 1);
		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
		curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
		curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
		curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
		curl_setopt($ch, CURLOPT_TIMEOUT, 120);
		curl_setopt($ch, CURLOPT_LOW_SPEED_LIMIT, 1);
		curl_setopt($ch, CURLOPT_LOW_SPEED_TIME, 60);
		if($proxy!="")
		{
			curl_setopt($ch, CURLOPT_PROXY,$proxy);
		}
		
		$fp = fopen ($filename, "w");
		curl_setopt ($ch, CURLOPT_FILE, $fp);
		
		curl_exec ($ch);	// execute the curl command 
		fclose($fp);
		
		$error = "";
		if (curl_error($ch)) $error = "Error ".curl_errno($ch).": ".curl_error($ch);
		
		curl_close ($ch);
		unset($ch);
		//$cf=file_get_contents($filename);
		return $error;
	}
	
	function GET($url,$cookiefile,$filename,$proxy="",$useragent="Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)")
	{
		global $configuration;
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 		
		curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
		curl_setopt($ch, CURLOPT_URL,$url);
		curl_setopt($ch, CURLOPT_TIMEOUT, 120);
		curl_setopt($ch, CURLOPT_LOW_SPEED_LIMIT, 1);
		curl_setopt($ch, CURLOPT_LOW_SPEED_TIME, 60);
		
		if($cookiefile!="") curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiefile);
		
		if($proxy!="")
		{
			curl_setopt($ch, CURLOPT_PROXY,$proxy);   
		}
		
		//curl_setopt($ch, CURLOPT_RANGE,"0-10000");			
		$fp = fopen ($filename, "w");
		curl_setopt ($ch, CURLOPT_FILE, $fp);
		
		curl_exec ($ch);
		fclose($fp);
		$error = "";
		if (curl_error($ch)) {
			$error = "Error ".curl_errno($ch).": ".curl_error($ch);
		}
		curl_close ($ch);
		unset($ch);
		return $error;
	}
}
?>
